<?php
namespace App\Http\Controllers\Laifei\Shop;

use App\Http\Controllers\Controller;
use App\Models\Shop;
use App\Models\Tools\Data;
use Illuminate\Support\Facades\DB;

class ShopDetailController extends Controller
{

    public function index()
    {

        $all = $this->all;
        $shop_id = $all['shop_id'];

        // 店铺信息
        $shop_message = Shop::shopMessage($shop_id);

        // 订单信息
        $order_message = DB::table('explore_order as eo')
            ->leftJoin('explore_channel as ec','eo.channel_id','=','ec.channel_id')
            ->where('eo.shop_id','=',$shop_id)
            ->select('eo.eo_id','eo.channel_id','ec.channel_id','eo.start_date','eo.end_date','eo.total_num','eo.remaining_num',
                'eo.distribution_num','eo.pending_num','eo.success_num','eo.failed_num','eo.status')
            ->get()
            ->map(function($item){
                $item->status_name = Data::$exploreOrderStatus[$item->status];
                return $item;
            })
            ->toArray();

        // 霸王餐
        $lottery = DB::table('lottery_activity as la')
            ->leftJoin('lottery_goods as lg','la.goods_id','=','lg.goods_id')
            ->where('la.shop_id','=',$shop_id)
            ->orderByDesc('la.created_at')
            ->select('la.act_id','lg.goods_name','la.created_at','la.status')
            ->get()
            ->map(function($item){
                $item->status = Data::$lotteryActivityStatus[$item->status];
                return $item;
            })
            ->toArray();

        return $this->setReturnJson(0,'success',[
            'shop'=>$shop_message,
            'order'=>$order_message,
            'lottery'=>$lottery,
            ]);

    }

}
